package com.jrx.anytxn.common.exception;

/**
 * 自定的运行时异常类  只能在服务启动时检查必要参数或配置出现错误时才能使用
 * @author zhaowg
 * @date 2018-07-19
 */
public class TxnRuntimeException extends  RuntimeException{

	private static final long serialVersionUID = 1L;

	private int errCode = 9999;
	
	private String errMsg = "default error";
	
	public TxnRuntimeException(){
		super();
	}
	
	public TxnRuntimeException(int errCode){
		super("errCode:"+errCode);
		this.errCode = errCode;
	}
	
	public TxnRuntimeException(String errMsg){
		super(errMsg);
		this.errMsg = errMsg;
	}
	
	public TxnRuntimeException(int errCode, String errMsg){
		super(errMsg);
		this.errCode = errCode;
		this.errMsg = errMsg;
	}
	
	public TxnRuntimeException(Throwable cause){
		super(cause);
		if(cause!=null){
			this.errMsg = cause.getMessage();
		}
	}
	
	public TxnRuntimeException(int errCode, Throwable cause){
		super(cause);
		this.errCode = errCode;
		if(cause!=null){
			this.errMsg = cause.getMessage();
		}
	}

	public int getErrCode() {
		return errCode;
	}

	public void setErrCode(int errCode) {
		this.errCode = errCode;
	}

	public String getErrMsg() {
		return errMsg;
	}

	public void setErrMsg(String errMsg) {
		this.errMsg = errMsg;
	}

	@Override
	public String toString() {
        String builder = "{\"errCode\"=\"" +
                errCode +
                "\", \"errMsg\"=\"" +
                errMsg +
                "\"}";
        return builder;
	}

	
}
